package org.dragonnova.iot.business.cloud.mq.service;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;
import javax.jms.TextMessage;

import org.dragonnova.iot.business.cloud.mq.message.TagMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * 
 * 
 * @description: 消息接收
 * @author songxy DateTime 2017年5月3日 下午1:30:40
 * @company winter
 * @email thinkdata@163.com
 * @version 1.0
 */
@Service
public class TagMessageReceiveService implements MessageListener {

	private final static Logger LOGGER = LoggerFactory
			.getLogger(TagMessageReceiveService.class);

	public void onMessage(Message message) {
		try {
			if (message instanceof ObjectMessage) {

				TagMessage msg = (TagMessage) ((ObjectMessage) message)
						.getObject();
				LOGGER.debug("Application: headers received: {}", msg);

			} else if (message instanceof TextMessage) {

				LOGGER.debug("Application: headers received: {}",
						((TextMessage) message).getText());

			}
		} catch (JMSException e) {
			e.printStackTrace();
		}
	}
}
